<?php

namespace app\admin\controller;

use app\common\Helpers\Result;
use think\captcha\facade\Captcha;
use think\Request;

// 组织架构
class StructController
{

    public function index(Request $request)
    {
        if($request->isPost()){
            $params = $request->post();
            $data = [
                [
                    'id' => 1,
                    'name' => '部门1',
                    'parent_id' => 0,
                    'levels' => '0',
                    'listsort' => 1,
                    'leader' => '',
                    'phone' => '',
                    'note' => '',
                    'status' => '1',
                    'create_time' => '2021-01-08 11:11:48',
                    'update_time' => '2021-01-08 11:11:48'
                ],
                [
                    'id' => 2,
                    'name' => '部门2',
                    'parent_id' => 1,
                    'levels' => '1',
                    'listsort' => 2,
                    'leader' => '',
                    'phone' => '',
                    'note' => '',
                    'status' => '1',
                    'create_time' => '2021-01-08 11:11:48',
                    'update_time' => '2021-01-08 11:11:48'
                ],
                [
                    'id' => 3,
                    'name' => '部门2',
                    'parent_id' => 1,
                    'levels' => '1',
                    'listsort' => 3,
                    'status' => '1',
                    'create_time' => '2021-01-08 11:11:48',
                    'update_time' => '2021-01-08 11:11:48'
                ]
            ];
            return Result::success('', $data, ['total' => 2]);
        }else{
            return view();
        }
    }
    public function tree()
    {
        $data = [
            [
                'id' => 100,
                'name' => '海燕集团',
                'parent_id' => 0
            ],
            [
                'id' => 101,
                'name' => '人事部',
                'parent_id' => 100
            ],
        ];
        return Result::success('获取成功', $data);
    }
}